package com.nulldev.util.web.dns.server.message;

public enum DNSRecordType {
	A(1),
    NS(2),
    CNAME(5),
    SOA(6),
    PTR(12),
    MX(15),
    AAAA(28),
    ALL(255),
    TXT(16);

    private final int numericCode;

    private DNSRecordType(int numericCode) {
        this.numericCode = numericCode;
    }

    /**
     * Get the numeric code used by the DNS protocol for this type of record.
     * @return Numeric code
     */
    public int getNumericCode() {
        return numericCode;
    }

    /**
     * Converts the numeric code for a record type into the enumerated value.
     * @param numericCode
     * @return Enumerated value
     */
    public static DNSRecordType getRecordType(int numericCode) {
        // Donald Knuth is muttering somewhere
        for (final DNSRecordType type : DNSRecordType.values()) {
            if (numericCode == type.getNumericCode()) {
                return type;
            }
        }
        throw new IllegalArgumentException("Illegal numeric code. Got " + numericCode + ".");
    }
}
